package com.example.onion.hxchat.mvvm;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;

import com.example.onion.hxchat.room.entity.Friend;
import com.example.onion.hxchat.room.entity.Info;
import com.example.onion.hxchat.room.repositorywc.InfoRepository;
import com.example.onion.hxchat.room.wcdatabase.MyDataBaseWc;
import com.example.room.entity.Team;

import java.util.ArrayList;
import java.util.List;

/**
 * @author:onion
 * @data: 2020/7/8
 */
public class InfoViewModel extends AndroidViewModel {

    //将“秒钟”这个字段用MutableLiveData包装起来
    //LiveData是一个抽象类，不能直接使用，所以通常我们使用它的直接子类MutableLiveData。
    private MutableLiveData<List<Info>> infos;
    InfoRepository repository;
    public InfoViewModel(@NonNull Application application) {
        super(application);
        repository = new InfoRepository(application);
    }

//    public boolean isExistInfo(String userId,String ownerUserId){
//        return repository.isExistInfo(userId,ownerUserId);
//    }
    /**
     * getter of teamList.
     * @return The LiveData of teamList
     */
    //不能删
    public MutableLiveData<List<Info>> getInfos() {
        if(infos == null) {
            infos = new MutableLiveData<>();
            getInfoFromDatabase();
        }
        return infos;
    }

    //不能删，删了就报错。。。
    public void getInfoFromDatabase(){
        List<Info> teams = new ArrayList<>();
        getInfos().setValue(teams);
    }

    public void insertInfo(Info... infos)
    {
        repository.insertMaster(infos);
    }

    public void insertJustLastInfo(String... strings)
    {
        repository.inserJustLastInfo(strings);
    }

    public LiveData<List<Info>> getAllInfos()
    {
        return repository.getAllInfos();
    }

    public LiveData<List<Info>> getUsersInfos(String userId)
    {
        return repository.getUsersInfo(userId);
    }
}
